﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<z.m.db.Order>" %>

<% if (ViewData["type"] == "header") {%>
<tr>
	<td rowspan="2"><%:Html.LabelFor(m=>m.ID) %></td>
	<td colspan="4"><%:Html.LabelFor(m=>m.Customer) %></td>
	<td rowspan="2"><%:Html.LabelFor(m=>m.Create_Date) %></td>
	<td rowspan="2"><%:Html.LabelFor(m=>m.Pay_Date) %></td>
	<td rowspan="2"><%:Html.LabelFor(m=>m.Order_Date) %></td>
	<td rowspan="2"><%:Html.LabelFor(m=>m.Ship_Date) %></td>
	<td rowspan="2"><%:Html.LabelFor(m=>m.Note) %></td>
	<td rowspan="2"><%:Html.LabelFor(m=>m.Address) %></td>
	<td rowspan="2" colspan="99">Controll</td>
</tr>
<tr>
	<td><%:Html.LabelFor(m=>m.Customer.First_Name) %></td>
	<td><%:Html.LabelFor(m=>m.Customer.Last_Name) %></td>
	<td><%:Html.LabelFor(m=>m.Customer.UserName) %></td>
	<td><%:Html.LabelFor(m=>m.Customer.Phone) %></td>
</tr>
<%} else if (ViewData["type"] == null) {
		int permission = 0;
		if (User.IsInRole("Mod")) {
			permission = 1;
		}
		if (User.Identity.Name == Model.Customer.UserName && !Model.Pay_Date.HasValue) {
			permission = 2;
		}
		if (User.IsInRole("Admin")) {
			permission = 3;
		}
		var attEdit = new Dictionary<string, object>();
		var att = new Dictionary<string, object>() {{"type","datetime-local"}};
		var attOrder_Date = new Dictionary<string, object>() { { "type", "datetime-local" } };
		if (permission < 3) {
			att.Add("readonly", "true");
		}
		if (permission < 2) {
			attEdit.Add("readonly", "true");
			attOrder_Date.Add("readonly", "true");
		}
%>
<tr id="or<%:Model.ID%>" data-id="<%:Model.ID%>">
	<td>
		<input name="ID" readonly="true" type="text" value="<%:Model.ID%>" />
	</td>
	<td><%:Html.DisplayFor(m=>m.Customer.First_Name) %></td>
	<td><%:Html.DisplayFor(m=>m.Customer.Last_Name) %></td>
	<td><%:Html.DisplayFor(m=>m.Customer.UserName) %></td>
	<td><%:Html.DisplayFor(m=>m.Customer.Phone) %></td>
	<td>
		<%:Html.TextBoxFor(m=>m.Create_Date,"{0:yyy-MM-ddTHH:mm}",htmlAttributes:att)%>
		<%:Html.ValidationMessageFor(m=>m.Create_Date) %>
	</td>
	<td>
		<%:Html.TextBoxFor(m=>m.Pay_Date,"{0:yyy-MM-ddTHH:mm}",htmlAttributes:att)%>
		<%:Html.ValidationMessageFor(m=>m.Pay_Date) %>
	</td>
	<td>
		<%:Html.TextBoxFor(m=>m.Order_Date,"{0:yyy-MM-ddTHH:mm}",htmlAttributes:attOrder_Date)%>
		<%:Html.ValidationMessageFor(m=>m.Order_Date) %>
	</td>
	<td>
		<%:Html.TextBoxFor(m=>m.Ship_Date,"{0:yyy-MM-ddTHH:mm}",htmlAttributes:att)%>
		<%:Html.ValidationMessageFor(m=>m.Ship_Date) %>
	</td>
	<td>
		<%:Html.TextAreaFor(m=>m.Note,htmlAttributes:attEdit)%>
		<%:Html.ValidationMessageFor(m=>m.Note) %>
	</td>
	<td>
		<%:Html.TextAreaFor(m=>m.Address,htmlAttributes:attEdit)%>
		<%:Html.ValidationMessageFor(m=>m.Address) %>
	</td>
	<td>
		<input value="Detail" type="button" onclick="
	openPopup('#popup1','<%:Url.Action("Administer", "Order_Detail", new {ID=Model.ID})%>	');" <%:Model.ID==0?"disabled":"" %>/>
	</td>
	<% if (permission <= 1) { %>
	<td>
		<div class="hidden" data-col="Messenger">
			<div class="close" onclick="closePopup(this.parentElement);destroyEditor();"></div>
			<div class="Administer">
				<% Response.Write(Model.Messenger); %>
			</div>
		</div>
		<input value="Messenger" type="button" onclick="showPopup('#or<%:Model.ID%> div[data-col=\'Messenger\']');" />
	</td>
	<%} if (permission == 1) { %>
	<td>
		<input type="button" value="Ship" onclick='ajaxTrBtn(event,"Ship");' />
	</td>
	<%} if (permission > 1) { %>
	<td>
		<div class="hidden" data-col="Messenger">
			<div class="close" onclick="closePopup(this.parentElement);destroyEditor();"></div>
			<div class="Administer">
				<textarea name="Messenger"><%:Model.Messenger %></textarea>
			</div>
		</div>
		<input value="Messenger" type="button" onclick="showPopup('#or<%:Model.ID%>	div[data-col=\'Messenger\']');installEditor('#or<%:Model.ID%>	div[data-col=\'Messenger\']');" />
	</td>
	<td>
		<input type="button" value="<%:Model.ID==0?"Add":"Save" %>" onclick='ajaxTrSubmit(event);' />
	</td>
	<td>
		<input type="button" value="Delete" onclick='ajaxTrBtn(event,"Delete");' />
	</td>
	<%} if (permission == 2) { %>
	<td>
		<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
			<input type="hidden" name="cmd" value="_xclick">
			<input type="hidden" name="business" value="kaibazax@yahoo.com">
			<input type="hidden" name="item_name"
				value="Pay for Order[<%:Model.ID%>]">
			<input type="hidden" name="item_number" value="<%:Model.ID%>">
			<input type="hidden" name="amount" value="3">
			<input type="hidden" name="currency_code" value="USD">
			<input type="hidden" name="return" value="order/pay" />
			<input type="hidden" name="rm" value="2" />
			<input type="submit" value="Pay" />
			<%--<input type="image" name="submit" border="0"
				src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
				alt="PayPal - The safer, easier way to pay online">--%>
		</form>
	</td>
	<%} if (permission > 2) { %>
	<td>
		<input type="button" value="Paid" onclick='ajaxTrBtn(event,"Paid");' />
	</td>
	<%}%>
</tr>
<%}%>